package com.ruoyi.common.utils.android;

import javax.crypto.Cipher;
import javax.crypto.SecretKey;
import javax.crypto.spec.IvParameterSpec;
import javax.crypto.spec.SecretKeySpec;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.io.UnsupportedEncodingException;

public class Main {


    private static String f970e = "4879448401768944";
    private static Main f;
    private SecretKeySpec a;

    /* renamed from: c  reason: collision with root package name */
    private IvParameterSpec f971c;
    private byte[] b = f970e.getBytes();

    /* renamed from: d  reason: collision with root package name */
    String f972d = "1311678945347452";

    public Main() {
        this.a = null;
        try {
            this.a = new SecretKeySpec(this.f972d.getBytes("UTF-8"), "AES");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        }
        this.f971c = new IvParameterSpec(this.b);
    }

    private byte[] a(String str, SecretKey secretKey, IvParameterSpec ivParameterSpec, byte[] bArr) {
        try {
            Cipher cipher = Cipher.getInstance(str);
            cipher.init(2, secretKey, ivParameterSpec);
            return cipher.doFinal(bArr);
        } catch (Exception e2) {
            e2.printStackTrace();
            return null;
        }
    }

    private byte[] b(String str, SecretKey secretKey, IvParameterSpec ivParameterSpec, byte[] bArr) {
        try {
            Cipher cipher = Cipher.getInstance(str);
            cipher.init(1, secretKey, ivParameterSpec);
            return cipher.doFinal(bArr);
        } catch (Exception e2) {
            e2.printStackTrace();
            return null;
        }
    }

    public static Main getInstance() {
        if (f == null) {
            synchronized (c.class) {
                if (f == null) {
                    f = new Main();

                    f.setsKey("5961962112341469");
                }
            }
        }
        return f;
    }

    public InputStream a(InputStream inputStream) {
        try {
            ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
            byte[] bArr = new byte[1024];
            while (true) {
                int read = inputStream.read(bArr, 0, 1024);
                if (read <= 0) {
                    return new ByteArrayInputStream(Main.getInstance().decrypt(byteArrayOutputStream.toByteArray()));
                }
                byteArrayOutputStream.write(bArr, 0, read);
            }
        } catch (Exception e2) {
            e2.printStackTrace();
            return null;
        }
    }



    public byte[] decrypt(byte[] bArr) {
        try {
            return com.ruoyi.common.utils.android.a.decodeBase64(a("AES/CBC/PKCS5Padding", this.a, this.f971c, com.ruoyi.common.utils.android.a.decodeBase64(bArr)));
        } catch (Exception e2) {
            e2.printStackTrace();
            return bArr;
        }
    }

    //5961962112341469


    public void setsKey(String str) {
        this.f972d = str;
        try {
            this.a = new SecretKeySpec(this.f972d.getBytes("UTF-8"), "AES");
        } catch (UnsupportedEncodingException e2) {
            e2.printStackTrace();
        }
    }



}
